/*
 * The Yard Utilties - http://www.theyard.net/
 * 
 * Copyright (c) 2008 by Vlideshow, Inc..  All Rights Resrved.
 * 
 * This library is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU Lesser General Public License as published by the Free Software 
 * Foundation; either version 2.1 of the License, or (at your option) any later 
 * version. 
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along 
 * with this library; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */
package net.theyard.components.netstreamsm
{
  import net.theyard.components.Utils;
  import flash.net.NetStream;

  internal class StoppingState implements StreamState
  {
    private var stateMachine:NetStreamStateMachine;
    public function StoppingState(stateMachine:NetStreamStateMachine)
    {
      Utils.ytrace("Starting state: " + this.toString());;
      this.stateMachine=stateMachine;
    }
    public function toString():String 
    {
      return NetStreamStateMachine.STATE_STOPPING;
    }
    public function play(ns:NetStream,name:Object, ...args):void
    {
      Utils.ytrace("Stopping stream; ignoring play request");
    }
    public function publish(ns:NetStream,flv:String,publishType:String):void
    {
      Utils.ytrace("Stopping stream; ignoring publish request");
    }
    public function togglePause(ns:NetStream):void
    {
      Utils.ytrace("Currently stopping stream; ignoring pause request");
    }
    public function stop(ns:NetStream):void
    {
      Utils.ytrace("Currently stopping stream; ignoring repeat stop request");
    }

    public function onDisconnect(ns:NetStream):void
    {
      Utils.ytrace("got a disconnect");
      stateMachine.gotoState(NetStreamStateMachine.STATE_DISCONNECTED);
      ns.close();
    }

    public function onPlayStart(ns: NetStream) : void
    {
      Utils.ytrace("Got onPlayStart but actually awaiting stop event.  Ignoring.");	
    }

    public function onPublishStart(ns: NetStream) : void
    {
      Utils.ytrace("Got onPublishStart but actually awaiting stop event.  Ignoring.");	
    }

    public function onPlayStop(ns: NetStream) :void
    {
      stateMachine.gotoState(NetStreamStateMachine.STATE_STOPPED);
    }

    public function onPublishStop(ns: NetStream) : void
    {
      stateMachine.gotoState(NetStreamStateMachine.STATE_STOPPED);

    }
    public function onReconnect() : void
    {
      stateMachine.gotoState(NetStreamStateMachine.STATE_STOPPED);			
    }
  }
}
